/*     */ package com.newcrm.webapi;
/*     */ 
/*     */ import com.newcrm.util.Util;
/*     */ import java.io.BufferedInputStream;
/*     */ import java.io.FileInputStream;
/*     */ import java.io.FileNotFoundException;
/*     */ import java.io.IOException;
/*     */ import java.io.InputStream;
/*     */ import java.io.OutputStream;
/*     */ import javax.servlet.ServletContext;
/*     */ import javax.servlet.ServletException;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import org.apache.log4j.Logger;
/*     */ 
/*     */ public class FileDownload extends AbstractHttpServlet
/*     */ {
/*     */   private static final long serialVersionUID = -4086280569184150244L;
/*  26 */   private static Logger logger = Logger.getLogger(FileDownload.class
/*  27 */     .getName());
/*     */ 
/*     */   public void doGet(HttpServletRequest request, HttpServletResponse response)
/*     */     throws ServletException, IOException
/*     */   {
/*  50 */     if (!checkLogin(request)) {
/*  51 */       super.showLoginPage(request, response);
/*  52 */       return;
/*     */     }
/*     */ 
/*  55 */     request.setCharacterEncoding("UTF-8");
/*     */ 
/*  60 */     String fileName = request.getParameter("fileName");
/*  61 */     String fileUrl = request.getParameter("fileUrl");
/*  62 */     String fileFolder = request.getParameter("fileFolder");
/*     */ 
/*  65 */     if ((fileUrl.indexOf("..") >= 0) || (fileUrl.indexOf("/") >= 0) || 
/*  66 */       (fileUrl.indexOf("\\") >= 0) || (fileUrl.indexOf("&") >= 0) || 
/*  67 */       (fileUrl.indexOf("?") >= 0) || 
/*  68 */       (fileUrl.toLowerCase().indexOf(".exe") >= 0) || 
/*  69 */       (fileUrl.toLowerCase().indexOf(".jsp") >= 0)) {
/*  70 */       return;
/*     */     }
/*     */ 
/*  73 */     if ((fileFolder != null) && (fileFolder.trim().length() > 0) && (
/*  74 */       (fileFolder.indexOf("..") >= 0) || (fileFolder.indexOf("/") >= 0) || 
/*  75 */       (fileFolder.indexOf("\\") >= 0) || 
/*  76 */       (fileFolder.indexOf("&") >= 0) || 
/*  77 */       (fileFolder.indexOf("?") >= 0) || 
/*  78 */       (fileFolder.toLowerCase().indexOf(".exe") >= 0) || 
/*  79 */       (fileFolder.toLowerCase().indexOf(".jsp") >= 0))) {
/*  80 */       return;
/*     */     }
/*     */ 
/*  84 */     int type = Util.str2Int(request.getParameter("type"));
/*  85 */     if (type <= 0) {
/*  86 */       type = 1;
/*     */     }
/*     */ 
/*  89 */     response.setContentType("application/x-download");
/*  90 */     response.setHeader("Content-Disposition", "attachment; filename=" + 
/*  91 */       fileName.replaceAll("(\\r|\\n)", ""));
/*     */ 
/*  93 */     OutputStream out = response.getOutputStream();
/*  94 */     String file = null;
/*  95 */     if (type == 2)
/*  96 */       file = getServletContext().getRealPath(
/*  97 */         "export/" + fileUrl);
/*  98 */     else if (type == 3)
/*  99 */       file = getServletContext()
/* 100 */         .getRealPath(
/* 101 */         "recording//" + fileFolder + "/" + 
/* 102 */         fileUrl);
/*     */     else
/* 104 */       file = getServletContext().getRealPath(
/* 105 */         "uploadfiles/" + fileUrl);
/*     */     try
/*     */     {
/* 108 */       returnFile(file, out);
/*     */     } catch (FileNotFoundException ex) {
/* 110 */       logger.warn("file not found : " + file, ex);
/*     */     } catch (IOException ex) {
/* 112 */       logger.warn("file IOException : " + file, ex);
/*     */     }
/*     */   }
/*     */ 
/*     */   private void returnFile(String filename, OutputStream out)
/*     */     throws FileNotFoundException, IOException
/*     */   {
/* 127 */     InputStream in = null;
/*     */     try {
/* 129 */       in = new BufferedInputStream(new FileInputStream(filename));
/* 130 */       byte[] buf = new byte[4096];
/*     */       int bytesRead;
/* 132 */       while ((bytesRead = in.read(buf)) != -1)
/*     */       {
/* 133 */         out.write(buf, 0, bytesRead);
/*     */       }
/*     */     } finally {
/* 136 */       if (in != null)
/* 137 */         in.close();
/*     */     }
/*     */   }
/*     */ 
/*     */   protected String getTagkey()
/*     */   {
/* 143 */     return null;
/*     */   }
/*     */ 
/*     */   protected AbstractAction getAddAction()
/*     */   {
/* 148 */     return null;
/*     */   }
/*     */ 
/*     */   protected AbstractAction getListAction()
/*     */   {
/* 153 */     return null;
/*     */   }
/*     */ 
/*     */   protected AbstractAction getShowAddPageAction()
/*     */   {
/* 158 */     return null;
/*     */   }
/*     */ 
/*     */   protected AbstractAction getUpdateAction(String id)
/*     */   {
/* 163 */     return null;
/*     */   }
/*     */ 
/*     */   protected AbstractAction getShowConfirmDestroyAction(String id)
/*     */   {
/* 168 */     return null;
/*     */   }
/*     */ 
/*     */   protected AbstractAction getDeleteAction(String id)
/*     */   {
/* 173 */     return null;
/*     */   }
/*     */ 
/*     */   protected AbstractAction getShowAction(String id)
/*     */   {
/* 178 */     return null;
/*     */   }
/*     */ 
/*     */   protected AbstractAction getShowUpdatePageAction(String id)
/*     */   {
/* 183 */     return null;
/*     */   }
/*     */ }

/* Location:           C:\E\referenceProject\CRM参考\qikebao\WEB-INF\lib\qikebao.jar
 * Qualified Name:     com.newcrm.webapi.FileDownload
 * JD-Core Version:    0.6.1
 */